package com.zjitc.redis;

import com.google.gson.Gson;
import com.zjitc.dao.AdminUserDao;
import com.zjitc.dao.UserDao;
import com.zjitc.pojo.Car;
import com.zjitc.pojo.Cart;
import com.zjitc.pojo.User;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/6/5 16:32
 * @description:
 */
public class AllSql {
  @Autowired
  public static void AllSql(Redis redis,UserDao userDao,AdminUserDao adminUserDao){
    Gson gson=new Gson();
    //用户缓存
    List<User> userList=userDao.findAllUser();
    String gsonUserList=gson.toJson(userList);
    redis.set("user",gsonUserList);

    List<Car> carList=userDao.findAll();
    String gsonCarList=gson.toJson(carList);
    redis.set("car",gsonCarList);

    List<Cart> cartList=userDao.findCartAll();
    for(Cart cart:cartList){
      Car car=userDao.findCarByCid(cart.getCarid());
      User user=userDao.findUserById(cart.getId());
      cart.setUser(user);
      cart.setCar(car);
    }
    String gsonCartList=gson.toJson(cartList);
    redis.set("cart",gsonCartList);

  }
}
